﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Model.Group;

namespace YouHP.Pages
{
    public class DiseaseList : BasePage
    {
        protected  List<string> mPingYin = new List<string>();
       
        protected override void ShowPage()
        {
            base.ShowPage();
            if(ErrorCount > 0) return;
            
            HandleCommon();
            if(ErrorCount > 0) return;
            
            if(IsPost) HandlePost();
            else HandleGet();
        }
        
        protected void HandleCommon()
        {
            this.AddLocation("疾病列表", "/DiseaseList.aspx");
            this.SetTitle("疾病列表");
           
            for (char c = 'A'; c <= 'Z'; c++)
            {
                mPingYin.Add(c.ToString());
            }
        }
        
        protected void HandlePost()
        {
            
        }

        protected List<DiseaseInfo> DiseaseDataList;
        protected int DiseaseCount = 105;
        protected int DiseasePageCount;
        protected int DiseasePageSize = 15;
        protected int DiseasePageIndex = 3;
        protected string DiseasePagingString;
        protected List<TopicInfo> TopicDataListHottest;
        protected List<TopicInfo> TopicDataListLatest;
        protected List<UserInfo> UserDataListLatest;
        protected string DszItemUrl = "/Disease.aspx?id=";
        protected string DszItemOperName = "查看";

#if GENDATA
        protected void HandleGet()
        {
            DiseasePageIndex = RequestTools.GetQueryInt("page", 1);
            DiseaseDataList = new List<DiseaseInfo>();
            for (int i = 1; i < 10; i++)
            {
                DiseaseInfo info = new DiseaseInfo();
                info.Id = 100 * i + i;
                info.Name = "疾病";
                info.Intro = "疾病简介疾病简介疾病简介疾病简介疾病简介疾病简介疾病简介";
                info.PatientId = 30;
                info.PatientCount = 2000;
                info.PatientAvatar = "/support/dnt/avatars/common/1.jpg";
                info.PatientName = "患者";
                DiseaseDataList.Add(info);
            }
            DiseasePageCount = Utils.GetPageCount(DiseaseCount, 10);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query,"page");
            
            DiseasePagingString = this.GetPagingString(DiseasePageIndex, DiseasePageCount,
                "/DiseaseList.aspx" + query, "page");

            TopicDataListHottest = new List<TopicInfo>();
            for (int i = 0; i < 5; i++)
            {
                TopicInfo info = new TopicInfo();
                info.Id = i;
                info.Title = "最热话题最热话题";
                info.ReplyCount = 10;
                TopicDataListHottest.Add(info);
            }

            TopicDataListLatest = new List<TopicInfo>();
            for (int i = 0; i < 5; i++)
            {
                TopicInfo info = new TopicInfo();
                info.Id = i;
                info.Title = "最新话题最新话题";
                info.ReplyCount = 10;
                TopicDataListLatest.Add(info);
            }

            UserDataListLatest = new List<UserInfo>();
            for (int i = 0; i < 5; i++)
            {
                UserInfo info = new UserInfo();
                info.Id = i;
                info.Avatar = "/support/dnt/avatars/common/1.jpg";
                info.UserName = "用户名";
                UserDataListLatest.Add(info);
            }

            string sel = RequestTools.GetQueryString("sel");
            if (sel == "dh")
            {
                this.DszItemUrl = "/DiseaseHistory/Index.aspx?dszid=";
                this.DszItemOperName = "选择";
            }
		}
#else
        protected void HandleGet()
        {
            int topiccnt = 8;
            TopicDataListHottest = TopicBLL.Instance.GetHottestTopic(topiccnt);
            TopicDataListLatest = TopicBLL.Instance.GetLastestTopic(topiccnt);
            UserDataListLatest = PatientBLL.Instance.GetLastestPatient(topiccnt);

            DiseasePageIndex = RequestTools.GetQueryInt("page", 1);
            DiseaseSearchCondtion cond = new DiseaseSearchCondtion();
            cond.FirstLetter = RequestTools.GetQueryString("firstLetter");

            DiseaseDataList = new List<DiseaseInfo>();

            DiseaseDataList = DiseaseBLL.Instance.GetDiseaseList(
               DiseasePageSize, DiseasePageIndex,
               cond, out DiseaseCount);

            DiseasePageCount = Utils.GetPageCount(DiseaseCount, 10);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query,"page");
            
            DiseasePagingString = this.GetPagingString(DiseasePageIndex, DiseasePageCount,
                "/DiseaseList.aspx" + query, "page");

            string sel = RequestTools.GetQueryString("sel");
            if (sel == "dh")
            {
                this.DszItemUrl = "/DiseaseHistory/Index.aspx?dszid=";
                this.DszItemOperName = "选择";
            }
		}
#endif
    }
}